package com.pft.web.util;

import android.content.Context;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbManager;
import android.support.annotation.NonNull;
import android.widget.Toast;

import java.util.HashMap;

public final class Utils
{
  private static Context mContext;
  
  private Utils()
  {
    throw new UnsupportedOperationException("u can't instantiate me...");
  }
  
  public static Context getContext()
  {
    if (mContext != null) {
      return mContext;
    }
    throw new NullPointerException("u should init first");
  }
  
  public static void init(@NonNull Context paramContext)
  {
    mContext = paramContext.getApplicationContext();
  }
  private static Toast toast;

  public static UsbDevice getUsbDeviceFromName(Context context, String usbName) {
    UsbManager usbManager = (UsbManager) context.getSystemService(Context.USB_SERVICE);
    HashMap<String,UsbDevice> usbDeviceList = usbManager.getDeviceList();
    return usbDeviceList.get(usbName);
  }

  public static void toast(Context context, String message) {
    if (toast == null) {
      toast = Toast.makeText(context, message, Toast.LENGTH_SHORT);
    } else {
      toast.setText(message);
    }
    toast.show();
  }
}
